@extends('backend::common.common_right')
@section('content')
    <style>
        #file {position: absolute;left: 0;width: 100%;height: 100%;top: 0;opacity: 0;z-index: 2;cursor: pointer;}
        #show_img{border:1px solid #eee;width:100%;height: 100%;}
    </style>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑贴图</h5>
                        <div class="ibox-tools">
                            <a type="button" class="close" href="{{url('backend/map/6/0')}}"> <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t"  action="{{url('backend/mapedit')}}" method="post" id="signupForm">
                            {{ csrf_field() }}
                            <input type="hidden" name="id" value="{{$map->id or ''}}">
                            <div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
                                <label class="col-sm-3 control-label">贴图标题：</label>
                                <div class="col-sm-8">
                                    <input type="text" value="{{ $map->title or '' }}" name="title" class="form-control" placeholder="标题" id="title">
                                    @if ($errors->has('title'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('title') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">贴图分类：</label>
                                <div class="col-sm-8">
                                    <div class="col-sm-6 row">
                                        <select class="form-control catsshow" name="cat_id1">
                                            @foreach($cats as $ca)
                                                <option value="{{$ca->id}}" @if($map->cat_id1 == $ca->id) selected @endif>{{$ca->catname}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('image') ? ' has-error' : '' }}" >
                                <label class="col-sm-3 control-label">图片：</label>
                                <div class="col-sm-2" id="aetherupload-wrapper">
                                    <img id="show_img" src="/storage/{{$map->image or 'banner/default.png'}}"  alt="">
                                    <input id="file" onchange="aetherupload(this,'image').success(someCallback).upload()" type="file" val=""/>
                                    <span style="font-size:12px;color:#aaa;" id="output"></span>
                                    <input type="hidden" name="image" id="savedpath" value="{{$map->image or ''}}">
                                    @if ($errors->has('image'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('image') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        someCallback = function(){
            var path = '/storage/'+this.savedPath;
            $("#show_img").attr('src',path);
        }
        $('.catsshow').change(function(){
            var id = $(".catsshow option:selected").val();
            $(".catrow").hide();
            $('.cats2show'+id).show();
        });
    </script>
@endsection